<?php
/*
+--------------------------------------------------------------------------
|   phpBIZ v3.0  full version
|   ========================================
|   by taft@wjl.cn yejun@wjl.cn
|   http://www.phpbiz.cn http://www.wjl.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 最后修改日期：2005-4-30 2006-2-8
|
+--------------------------------------------------------------------------
*/
!class_exists('Debug') && exit('Forbidden');
$idx = new Sharelink;
class Sharelink
{
	function Sharelink()
	{
		global $BIZ,$INCOME,$CONF,$_LEVEL;
		
		$this -> upload_dir = stripslashes($CONF['upload_dir']);
		$this -> seller_data = new manager($BIZ->seller['seller_id']);

		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )	unset($$k);
		
	    //--------------------------------------------
        // Check viewing permissions, etc
	    //--------------------------------------------
						
		if ( empty($BIZ->seller['seller_id']) or $BIZ->seller['seller_id']=="" or $BIZ->seller['seller_id']==0 )
		{
			$BIZ->error( "用户没有登陆，不能使用此功能","?act=Login&code=00" );
		}
		
		if( !$this -> seller_data->check($INCOME[act]) )
            $BIZ -> error("该等级用户不享有该功能。");

	    if( $BIZ->seller['seller_check_status']=='uncheck' )
		{
			$this -> seller_data->control_panel("nocharge");
		}elseif( ($data=$this -> seller_data->get_seller_data("end_time,property_id"))&& $data['end_time']<time()&&$_LEVEL[$data['property_id']][1]>0)
		{
			$this -> seller_data->control_panel("due");
		}else
		{
			$BIZ -> assign('code',$INCOME['code']);
			$BIZ-> nav_link[] =array ("商家控制台","index.php?act=Promote");
			switch($INCOME['code'])
			{
				case '00':     // display general seller info
				   $this -> seller_data->control_panel();
				   break;
				case '01':
					$BIZ -> nav_link[] = array("友情链接管理","");
					$this ->link_form();
				  break;
				case 'addsl':
					$BIZ -> nav_link[] = array("添加友情链接","");
					break;
				case 'doaddsl':
					$this -> do_add_link();
				   break;
				case 'delsl':
					$this -> del_sl();
				  break;
				case 'mdsl':     // modify sharelink
					$BIZ -> nav_link[] = array("修改友情链接","");
					$this -> modify_sl();
				   break;
				case 'domdsl':  // do modify sharelink
					$this -> do_modify_sl();
				  break;
				default:
				  $this -> seller_data->control_panel();
			}
		}
		$BIZ -> output('Sharelink.tpl');
	}
	function link_form()
	{
		global $BIZ,$DB;
		$DB -> db_query("SELECT * FROM biz_sharelink WHERE seller_id=".$BIZ->seller[seller_id]." ORDER BY rank");
		while( $rs=$DB->db_fetch_row() )
		{
			$sl[]=array($rs[name],$rs[rank],$rs[url],$rs[descrip],$rs[id]);
		}
		$BIZ -> assign("sl",$sl);

	}
	function do_add_link()
	{
		global $INCOME,$BIZ,$DB;
		$sl = $INCOME[sl];
		if( !$sl[name] || !$sl[url] )
		{
			$BIZ -> error();
		}
		$sl[rank]=intval($sl[rank]);
		$sl[seller_id]=$BIZ->seller[seller_id];
		$DB -> db_form_insert("biz_sharelink",$sl);
		$BIZ ->redirect_screen("恭喜！您已经成功地添加了友情链接。","?act=Sharelink&code=01");

	}
	function del_sl()
	{
		global $INCOME,$BIZ,$DB;
		$del_db = @implode(",",$INCOME[sid]);

		if( count($INCOME[sid]) ) $DB -> db_query("DELETE FROM biz_sharelink WHERE id IN (".$del_db.")");
		$BIZ ->redirect_screen("恭喜！您已经成功地更新了友情链接。","?act=Sharelink&code=01");
	}
	function modify_sl()
	{
		global $INCOME,$BIZ,$DB;
		$DB -> db_query("SELECT * FROM biz_sharelink WHERE id=".intval($INCOME[sid]),1);

		$BIZ -> assign("md",$DB -> db_fetch_row() );
	}
	function do_modify_sl()
	{
		global $INCOME,$BIZ,$DB;

		$sl = $INCOME[mdsl];
		$DB ->db_form_update("biz_sharelink",$sl," id=".intval($INCOME[sid]));
		$BIZ ->redirect_screen("恭喜！您已经成功地修改了友情链接。","?act=Sharelink&code=01");

	}
}
?>